function nav_name(config)
{
	return config.force_all?"list_nav_level_all":"list_nav_level";
}

exports.add=[{
	_type:"controller",
	_config_details: {
		
	},
	_config: {
		name: "NavRoot",
		index_view:"index",
		parent_id:null,
		force_all:false,// Force all pages, not only "show in navigation"
		show_logo_before:0,
		helpers_before:[],
		show_logo_after:0,
		limit:undefined,
		helpers_after:[]
	},
	/**
	 * Controller: NavRoot.index
	 *		Renders root navigation
	 *
	 * Returns:
	 *		HTML
	 */
	index: function(config) {
		var t=this;
		this.F("Nav","calc");
		this.configNavRoot=config;
		this.nav_root=this.site.models.Page.List(nav_name(config),{parent_id:config.parent_id,user_id:this.uid});
		if (config.limit) this.nav_root.splice(config.limit,this.nav_root.length-config.limit);
		this.nav_root.forEach(function(n) {
			if (t.calc_pages.active[n.id]) n.active=1;
			if (n.alias==t.action) n.fully_active=1;
			if (n.alias=="/index/") n.alias="/";
		});
		["before","after"].forEach(function(s) {
			t["nav_root_helpers_"+s]="";
			if (config["helpers_"+s].length==0) return;
			config["helpers_"+s].forEach(function(a) {
				var arr=a.match(/^(\w+)\.(\w+)$/);
				t["nav_root_helpers_"+s]+=t.C(arr[1],arr[2]);
			});
		});
		return this.Cview();
	}
}];

